#include "pid.h"

float pid_cacl(pid_controller *pid,float get){
  pid->lasterr=pid->err;
  pid->get=get;
  pid->err=pid->set-pid->get;
  pid->pout = pid->kp * pid->err;
  pid->iout += pid->ki * pid->err;
  pid->dout = pid->kd * (pid->err - pid->lasterr);
  if(pid->iout>pid->vimax)pid->iout=pid->vimax;
  pid->out = pid->pout + pid->iout + pid->dout;
  return pid->out;
}
